package com.share.user.api;

import com.share.common.core.domain.Result;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.security.annotation.InnerAuth;
import com.share.common.security.annotation.RequiresLogin;
import com.share.user.domain.UpdateUserLogin;
import com.share.user.domain.UserInfo;
import com.share.user.service.IUserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 处理微信小程序端的用户的相关接口
 */
@RestController
@RequestMapping("/userInfo")
@Slf4j
public class UserInfoApiController extends BaseController {

    @Autowired
    private IUserInfoService userInfoService;

    /**
     * 处理微信用户登录请求
     */
    @Operation(summary = "小程序授权登录")
    @GetMapping("/wxLogin/{code}")
    public Result<UserInfo> wxLogin(@PathVariable String code){
        log.info("小程序授权登录:{}",code);
        UserInfo userInfo = userInfoService.wxLogin(code);
        return Result.ok(userInfo);
    }

    /**
     * 更新用户登录信息 id ip地址 最后登录时间等
     * @param updateUserLogin
     * @return
     */
    @Operation(summary = "更新用户登录信息")
    @InnerAuth
    @PutMapping("/updateUserLogin")
    public Result<Boolean> updateUserLogin(@RequestBody UpdateUserLogin updateUserLogin) {
        return Result.ok(userInfoService.updateUserLogin(updateUserLogin));
    }


    //判断用户是否免押金 模拟调用微信api
    @Operation(summary = "是否免押金")
    @GetMapping("/isFreeDeposit")
    public AjaxResult isFreeDeposit(){
        log.info("判断用户是否免押金");
        Boolean freeDeposit = userInfoService.isFreeDeposit();
        return AjaxResult.success(freeDeposit);
    }
}
